//
//  MyCollectionQuestionAnswerCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MyCollectionQuestionAnswerCell.h"


@interface MyCollectionQuestionAnswerCell ()

/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**左边文字*/
@property (nonatomic,strong)UILabel*leftLabel;
/**右边图片*/
@property (nonatomic,strong)UIImageView*rightImage;
/**消息数量*/
@property (nonatomic,strong)UILabel*numberLabel;
@end

@implementation MyCollectionQuestionAnswerCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)setModel:(PersonalHomePageModel *)model{
    _model = model;
    self.userView.userName.text = model.userName;
    self.userView.iconImage.image = IMAGE_NAMED(model.userImage);
}
-(void)createUI{
    UILabel * titleLabel = UILabel.new;
    titleLabel.font = SYSTEMFONT(14);
    titleLabel.textColor = UIColorFromRGB(0x454F44);
    titleLabel.text = @"提出问题";
    
    UIView * contenView = [self createContenView];
    
    UIView * numberView = [self createMeseageView];
    
    [self addSubview:self.userView];
    [self addSubview:titleLabel];
    [self addSubview:contenView];
    [self addSubview:numberView];

    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];

    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.userView.mas_bottom);
    }];
    
    [contenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(4);
    }];
    [numberView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(-16);
        make.top.mas_equalTo(contenView.mas_bottom).offset(9);
    }];

}
-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        _userView.deleButton.hidden = YES;
    }
    return _userView;
}

-(UILabel*)leftLabel{
    if(!_leftLabel){
        _leftLabel=[UILabel new];
        _leftLabel.textColor = UIColorFromRGB(0x273323);
        _leftLabel.font = SYSTEMFONT(16);
        _leftLabel.numberOfLines = 0;
        _leftLabel.text = @"做烤鸡的时候该怎么做？简单容易上手，老人孩子都喜欢…";
    }
    return _leftLabel;
}
-(UIImageView*)rightImage{
    if(!_rightImage){
        _rightImage=[UIImageView new];
        _rightImage.image = IMAGE_NAMED(@"dynamicDefut");
    }
    return _rightImage;
}

-(UILabel*)numberLabel{
    if(!_numberLabel){
        _numberLabel=[UILabel new];
        _numberLabel.textColor = UIColorFromRGB(0x959E97);
        _numberLabel.font = SYSTEMFONT(12);
        _numberLabel.text = @"658";
    }
    return _numberLabel;
}
-(UIView *)createContenView{
    UIView * view = UIView.new;
    
    ViewBorderRadius(view, 5, 0.5, UIColorFromRGB(0x959E97));
    
    [view addSubview:self.leftLabel];
    [view addSubview:self.rightImage];
    
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.bottom.mas_equalTo(self.rightImage);
        make.right.mas_equalTo(self.rightImage.mas_left).offset(-16);
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(8);
        make.bottom.mas_equalTo(-8);
        make.width.mas_equalTo(72);
        make.height.mas_equalTo(57);
    }];
    
    return view;
}
-(UIView *)createMeseageView{
    UIView * view = UIView.new;
    
    UIButton * imageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [imageBtn setImage:IMAGE_NAMED(@"home_mesae") forState:UIControlStateNormal];
    
    [view addSubview:imageBtn];
    [view addSubview:self.numberLabel];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0);
    }];
    [imageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerY.mas_equalTo(0);
        make.right.mas_equalTo(self.numberLabel.mas_left).offset(-4);
        make.width.height.mas_equalTo(16);
    }];
    
    return view;
}
@end
